1. Field of the Invention
The present invention relates generally to a method of encoding numeric data and manipulating the same. More particularly, the present invention relates to a method of encoding numeric data as a variable-length, null-terminated string and manipulating the variable-length, null-terminated string.
2. Description of the Prior Art
It is well known in the art to store numeric data as a fixed-length data type. For example, the C programming language defines three data types for storing numeric data, namely, xe2x80x9cint,xe2x80x9d xe2x80x9cfloatxe2x80x9d and xe2x80x9cdouble.xe2x80x9d An additional data type, xe2x80x9cchar,xe2x80x9d is used for storing characters. A fixed amount of memory is allocated to each of these data types, and, therefore, a finite range of values is associated with each data type. Furthermore, each of these data types may be modified by one or more of the modifiers xe2x80x9cshort,xe2x80x9d xe2x80x9clong,xe2x80x9d xe2x80x9csignedxe2x80x9d and xe2x80x9cunsigned,xe2x80x9d which further define the memory allocated and the range. For a modern personal computer (xe2x80x9cPCxe2x80x9d), Table 1, below, summarizes the memory allocation and range for several of the data types described above:
Insofar as the foregoing data types have defined limitations in terms of memory allocation and range, the use of such data types requires a programmer to anticipate the range of the data intended to be stored therein. This is not always possible. Additionally, any range anticipated may be accurate at the time that software is authored, but the range may change over time.
Storage of very large or very small numbers having very few significant digits results in highly inefficient memory usage. Additionally, performing mathematical operations on variables having dissimilar data types may result in unexpected and unforeseeable errors. Without proper trapping and handling, these errors may be silently compounded.
It is an object of the present invention to provide a method of encoding numeric data and manipulated the encoded numeric data. It is a further object of the present invention to efficiently store numeric data. It is a further object of the present invention to provide a method of encoding numeric data which permits such data to be manipulated as conventionally stored numeric data. It is a still further object of the present invention to provide a method of encoding numeric data that can be sorted according to conventional sorting routines.
These and other beneficial objects of the present invention are most effectively attained by providing a method of encoding a numeric data as a variable-length, NULL-terminated string, wherein the first byte represents a sign of the numeric data, the second byte represents an exponent of the numeric data and the following bytes represent a mantissa of the numeric data. Each of the bytes, except for the first byte, is biased to avoid storage of a zero or NULL byte, which, according to the present invention is a terminating value. The first byte, in addition to indicating the sign of the numeric data, indicates whether the numeric data has a zero value or a NULL value, which is generally not recognized in standard computer programming languages, such as C.